package tests

import (
	"fmt"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestTemplate(t *testing.T) {
	// 定义 SQL 模板（简单版）
	var file = "/Users/rdn/Documents/annotation/gin-admin/internal/app/infra/template/templates/query_check_prompt_by_user.sql"
	var conds = map[string]any{
		"fields": "id, name, email",
		"ids":    "101, 205, 307",
		"status": "active",
		"name":   "", // 尝试设为 "" 看条件是否消失
		"limit":  10,
	}
	sql, err2 := template.SqlFromTemplate(file, conds)
	assert.NoError(t, err2)
	fmt.Println("生成的 SQL:")
	fmt.Println(sql)
}

func TestCopier(t *testing.T) {
	// Source struct with int field
	type Source struct {
		ID   int
		Name string
		Age  int
	}

	// Target struct with *int field
	type Target struct {
		ID   int
		Name *string
		Age  *int
	}

	// Test case 1: Normal int value
	source1 := Source{
		ID:   1,
		Name: "Alice",
		Age:  25,
	}

	var target1 Target
	err := copier.Copy(&target1, &source1)
	if err != nil {
		fmt.Printf("Error in test case 1: %v\n", err)
	} else {
		fmt.Printf("Test case 1 - Source: %+v\n", source1)
		fmt.Printf("Test case 1 - Target: %+v\n", target1)
		if target1.Name != nil {
			fmt.Printf("Test case 1 - Name value: %s\n", *target1.Name)
		} else {
			fmt.Println("Test case 1 - Name is nil")
		}
	}
	fmt.Println()

	// Test case 2: Zero int value
	source2 := Source{
		ID:   2,
		Name: "",
		Age:  0,
	}

	var target2 Target
	err = copier.Copy(&target2, &source2)
	if err != nil {
		fmt.Printf("Error in test case 2: %v\n", err)
	} else {
		fmt.Printf("Test case 2 - Source: %+v\n", source2)
		fmt.Printf("Test case 2 - Target: %+v\n", target2)
		if target2.Name != nil {
			fmt.Printf("Test case 2 - Name value: %s\n", *target2.Name)
		} else {
			fmt.Println("Test case 2 - Name is nil")
		}
	}
	fmt.Println()

	// Test case 3: Negative int value
	source3 := Source{
		ID:   3,
		Name: "Charlie",
		Age:  -5,
	}

	var target3 Target
	err = copier.Copy(&target3, &source3)
	if err != nil {
		fmt.Printf("Error in test case 3: %v\n", err)
	} else {
		fmt.Printf("Test case 3 - Source: %+v\n", source3)
		fmt.Printf("Test case 3 - Target: %+v\n", target3)
		if target3.Name != nil {
			fmt.Printf("Test case 3 - Name value: %s\n", *target3.Name)
		} else {
			fmt.Println("Test case 3 - Name is nil")
		}
	}
}
